package com.education.user.controller.login;


import com.education.common.pojo.AjaxResult;
import com.education.user.pojo.Classes;
import com.education.user.service.ClassService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;


/**
 * 班级表
 *
 * @date 2020-11-14 09:57:53
 */
@RestController
@RequestMapping("/user/class")
public class ClassController {

    @Autowired
    private ClassService classService;

    //查询全部数据
    @GetMapping("/queryList")
    public AjaxResult queryList(Classes classes) {
        List<Classes> list = classService.select(classes);
        return AjaxResult.success(list);
    }

    //添加数据
    @PostMapping("/insert")
    public AjaxResult insert(@RequestBody Classes classes) {
        classes.setCreateTime(new Date());
        int i = classService.insert(classes);
        if (i > 0) return AjaxResult.success("添加成功");
        return AjaxResult.error("添加失败");
    }

    //修改数据
    @PostMapping("/update")
    public AjaxResult update(@RequestBody Classes classes) {
        int i = classService.update(classes);
        if (i > 0) return AjaxResult.success("修改成功");
        return AjaxResult.error("修改失败");
    }

    //批量删除
    @GetMapping("/delete")
    public AjaxResult delete(int id) {
        int i = classService.delete(id);
        if (i > 0) return AjaxResult.success("删除成功");
        return AjaxResult.error("删除失败");
    }
}
